<template>
    <div class="app-container">
        <!--搜索框表单-->
        <el-form :inline="true" class="demo-form-inline">
            <!-- 医院名称 -->
            <el-form-item>
                <el-input v-model="searchObj.hosname" placeholder="点击输入医院名称"/>
            </el-form-item>

            <!-- 开始日期 -->
            <el-form-item>
                <el-date-picker
                    v-model="searchObj.reserveDateBegin"
                    type="date"
                    placeholder="选择开始日期"
                    value-format="yyyy-MM-dd"/>
            </el-form-item>

            <!-- 截止日期 -->
            <el-form-item>
                <el-date-picker
                    v-model="searchObj.reserveDateEnd"
                    type="date"
                    placeholder="选择截止日期"
                    value-format="yyyy-MM-dd"/>
            </el-form-item>

            <!-- 查询按钮 -->
            <el-button
                :disabled="btnDisabled"
                type="primary"
                icon="el-icon-search"
                @click="showChart()">
                查询
            </el-button>
        </el-form>

        <!-- 图表 -->
        <div class="chart-container">
            <!-- 显示图表 -->
            <div id="chart" ref="chart" class="chart" style="height:500px;width:100%"/>
        </div>
    </div>
</template>

<script>
import echarts from 'echarts'
import statistics_Api from '@/api/statistics/orderStatistics'

export default {

    data() {
        return {
            searchObj: {
                hosname: '',
                reserveDateBegin: '',
                reserveDateEnd: ''
            },

            btnDisabled: false,
            chart: null,
            title: '',
            xData: [], // x轴数据
            yData: [] // y轴数据
        }
    },

    methods: {
        // 初始化图表数据
        showChart() {
            statistics_Api.getCountMap(this.searchObj).then(response => {
                this.yData = response.data.countList
                this.xData = response.data.reserveDateList
                this.setChartData()
            })
        },

        setChartData() {
            // 基于准备好的dom，初始化echarts实例
            var myChart = echarts.init(document.getElementById('chart'))
            // 指定图表的配置项和数据
            var option = {
                title: {
                    text: this.title + '挂号量统计'
                },
                tooltip: {},
                legend: {
                    data: [this.title]
                },
                xAxis: {
                    data: this.xData
                },
                yAxis: {
                    minInterval: 1
                },
                series: [{
                    name: this.title,
                    type: 'line',
                    data: this.yData
                }]
            }
            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option)
        },
    }
}
</script>
